<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:decorate template="/resources/template/modelo.xhtml">

        <ui:define name="centro">
            <f:view encoding="ISO-8859-1"> 
                <f:metadata>
                    <f:viewParam name="id" value="#{trabalhoGSBean.trabalho}"/>
                </f:metadata> 
                <h:form id="form">
                    <p:messages id="messages1" showDetail="true" autoUpdate="true" closable="true" escape="false" /> 
                    <p:panel id="pInfBasicas"  header="Edição de Trabalhos em Gestão Social" style="width: 95%;background-color: #E0E0E0" >
                        <div algin="center" >
                            <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                <h:outputText value="Título: " style="width: 20%" />
                                <p:inputText value="#{trabalhoGSBean.trabalho.titulo}" style="width: 80%" /> 

                                <h:outputText value="Tipologia: " />
                                <p:selectOneMenu value="#{trabalhoGSBean.trabalho.tipologia}"   
                                                 effect="fade" style="width:80%"  filter="true" filterMatchMode="startsWith" >  
                                    <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"  />  
                                    <f:selectItems value="#{trabalhoGSBean.tipologias}" var="tc" itemLabel="#{tc.toString()}" itemValue="#{tc.toString()}" />
                                </p:selectOneMenu> 
                                <h:outputText value="Instituição de Realização do Trabalho:" style="width: 20%" />
                                <p:selectOneMenu value="#{trabalhoGSBean.trabalho.instituicao.id}" style="width:80%"  
                                                 effect="fade"  filter="true" filterMatchMode="startsWith" >  
                                    <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"  />  
                                    <f:selectItems value="#{instituicaoBean.listaInstituicoes}" var="inst" itemLabel="#{inst.nome}, #{inst.municipio},  #{inst.estado}" itemValue="#{inst.id}" />
                                </p:selectOneMenu> 
                                <h:outputText value="Objetivo da Avaliação: " style="width: 20%" /> 
                                <p:inputText value="#{trabalhoGSBean.trabalho.objetivoAvaliacao}" style="width: 80%" /> 
                                <h:outputText value="Tipo de Avaliação" style="width: 20%" />
                                <p:selectOneMenu value="#{trabalhoGSBean.trabalho.tiposDeAvaliacao}" style="width:80%"  
                                                 effect="fade"  filter="true" filterMatchMode="startsWith" editable="true" onchange="">  
                                    <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"  />  
                                    <f:selectItems value="#{trabalhoGSBean.tipoAvaliacoes}" var="ta" itemLabel="#{ta}" itemValue="#{ta}" />
                                </p:selectOneMenu> 


                            </h:panelGrid>
                            <h:panelGrid columns="1" width="99%" style="text-align: center"  >
                                <h:outputText value="Resumo do Trabalho (Limite de 1500 caracters):"/>
                                <p:editor value="#{trabalhoGSBean.trabalho.resumo}" width="900"  maxlength="1500" style="text-align: center" />

                                <h:outputText value="Descrição do Método (Limite de 1500 caracters):"/>
                                <p:editor value="#{trabalhoGSBean.trabalho.descricaoMetodologia}" width="900" maxlength="1500"  />


                                <h:outputText value="Outras Observações (Limite de 1500 caracters) :" />
                                <p:editor value="#{trabalhoGSBean.trabalho.outrasObservacoes}" width="900" maxlength="1500"  />

                            </h:panelGrid>
                            <br/>
                            <p:panel header="Palavras-chave" style="background-color: #D0D0D0;font-size: large " >


                                <h:panelGrid columns="2" width="99%" >
                                    <p:selectOneMenu id="temas" value="#{trabalhoGSBean.temaSelecionado.id}" style="width:95%"  
                                                     filter="true" filterMatchMode="startsWith"  >  
                                        <f:selectItem itemLabel="Selecione" itemValue=""   />  
                                        <f:selectItems value="#{trabalhoGSBean.listaTemas}" var="t" itemLabel="#{t.tema}" itemValue="#{t.id}" />
                                    </p:selectOneMenu> 
                                    <p:commandButton value="Cadastrar" action="#{trabalhoGSBean.addPalavraChaveEdicao()}" update="temas, tCadastrados"  >

                                    </p:commandButton>
                                </h:panelGrid>
                                <p:commandLink oncomplete="dPC.show()" update=":form:display3" >
                                    Não encontrou a palavra-chave?
                                </p:commandLink>
                                <br/><br/>

                                <p:panel header="Palavras-chave Cadastradas" style="background-color: #A0A0A0" >
                                    <p:dataTable id="tCadastrados" value="#{trabalhoGSBean.trabalho.palavrasChave}" var="te" style="width: 70%" >
                                        <p:column headerText="Palavra-chave" style="width: 98%">
                                            #{te.tema}
                                        </p:column>
                                        <p:column headerText="Remover">
                                            <p:panelGrid columns="1" style="text-align:center">
                                                <p:commandButton action="#{trabalhoGSBean.removerPalavraChaveEdicao()}" icon="ui-icon-trash"  style="width: 2%" update="tCadastrados" >
                                                    <f:setPropertyActionListener target="#{trabalhoGSBean.temaSelecionado}" value="#{te}" />

                                                </p:commandButton>
                                            </p:panelGrid>     

                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                            </p:panel>
                            <br/>
                            <p:panel header="Autores" style="background-color: #D0D0D0;font-size: large " >


                                <h:panelGrid columns="2" width="99%" >
                                    <p:selectOneMenu id="autores" value="#{trabalhoGSBean.autorSelecionado.id}" style="width:95%"  
                                                     filter="true" filterMatchMode="startsWith"  >  
                                        <f:selectItem itemLabel="Selecione" itemValue=""   />  
                                        <f:selectItems value="#{trabalhoGSBean.listaAutores}" var="a" itemLabel="#{a.nome}" itemValue="#{a.id}" />
                                    </p:selectOneMenu> 
                                    <p:commandButton value="Cadastrar" action="#{trabalhoGSBean.addAutorEdicao()}" update="autores, aCadastrados"  >

                                    </p:commandButton>
                                </h:panelGrid>
                                
                                <br/><br/>

                                <p:panel header="Autores Cadastrados" style="background-color: #A0A0A0;text-align:center;white-space: normal;" >
                                    <p:dataTable id="aCadastrados" value="#{trabalhoGSBean.trabalho.autores}" var="autor" style="width: 100%" >
                                        <p:column headerText="Nome" style="width: 98%;white-space: normal">
                                            #{autor.nome} #{autor.instituicaoAutor.nome}
                                        </p:column>
                                        
                                        <p:column headerText="Remover">
                                            <p:panelGrid columns="1" style="text-align:center">
                                                <p:commandButton action="#{trabalhoGSBean.removerAutorEdicao()}" icon="ui-icon-trash"  style="width: 2%" update="aCadastrados" >
                                                    <f:setPropertyActionListener target="#{trabalhoGSBean.autorSelecionado}" value="#{autor}" />

                                                </p:commandButton>
                                            </p:panelGrid>     

                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                            </p:panel>
                            
                            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" escape="false" /> 
                            <br/>
                            <b><h3>Como encontrar este trabalho:</h3></b>
                            <h:panelGrid columns="2" width="99%" >
                                <h:outputText value="Link:" style="width: 20%" />
                                <p:inputText value="#{trabalhoGSBean.trabalho.link}" style="width: 80%" />
                                <h:outputText value="Outro:" style="width: 20%" />
                                <p:inputText value="#{trabalhoGSBean.trabalho.textoOndeEncontrar}" style="width: 80%" />
                                <h:outputText value="Fazer upload do PDF: " style="width: 20%" />
                                <h:form enctype="multipart/form-data" >
                                    <p:fileUpload fileUploadListener="#{trabalhoGSBean.doUploadPDF}" mode="advanced" label="Adicionar" update="messages" auto="true"  allowTypes="/(\.|\/)(pdf)$/" multiple="false" style="width: 80%;background-color: #E0E0E0" />  
                                    <p:growl id="messages" showDetail="true" escape="false"/>  
                                </h:form>

                            </h:panelGrid>




                        </div>
                    </p:panel>
                    <h:panelGrid columns="2" width="99%"  style="text-align:center" >
                        <p:commandButton value="Cadastrar" action="#{trabalhoGSBean.editar()}" ajax="false" />
                        <p:commandButton value="Cancelar" action="/indexSistema.xhtml" ajax="false" />
                    </h:panelGrid>

                    <p:dialog id="dPalavraChave" header="Cadastrar Palavra-Chave" widgetVar="dPC" >  
                        <p:panel id="display3"  >
                            <b><h:outputText value="Palavra-Chave:" /></b><br/>
                            <h:inputText value="#{temaBean.tema.tema}" />
                            <p:commandButton actionListener="#{temaBean.cadastroTema()}" oncomplete="dPC.hide()" value="Cadastrar" update=":form:temas" >
                                <f:setPropertyActionListener target="#{trabalhoGSBean.listaTemas}" value="#{null}" />
                            </p:commandButton>
                        </p:panel>

                    </p:dialog>  

                </h:form>    
            </f:view>
        </ui:define>
    </ui:decorate>
</html>